Solving the "Maze Avenger" Saving/Loading Problem
By Adam Trionfo
October 21, 2011

This document is based on message #10375 called " RE: Trouble Saving/Loading to 
Address and Arrays."  The message was posted to the Bally Alley Discussion 
Group on March 8, 2011.

Mike White put me onto the information that allowed me to solve the 
saving/loading problem with "Maze Avenger."  It really helps that I just 
recently learned how to make an autorun AstroBASIC program, as the technique to 
do both is nearly identical.

Mike gave me the correct solution.  The syntax is located in his BASIC 
Tutorial, "Tricks of the Trade #3," available here,

http://www.ballyalley.com/basic/tutorials/tricks_of_the_trade_03.pdf

This gives an explanation of AutoRun and why it works.  This same EXACT 
technique is used to eliminate the "WHAT?" loading error.

First, here is how to solve the trouble that will work with just about any 
program (perhaps all programs), as it saves all of RAM:

PRINT ";STOP";:PRINT %(16384),2000

That's it.  Now the program loads and doesn't give the error "WHAT?" message.  
In order to have an AutoRun program, the user types this command:

PRINT ";RUN";:PRINT %(16384),2000

The two commands are very similar!

We're being very heavy handed with this solution.  It works, but we don't 
really HAVE to save everything.  We just want to save the BASIC program and the 
machine language routine.  "Maze Avenger's" ML Routine begins at:

20237 = $4F0D

The ML routine is stored through:

20278 = $4F36

We really only need to save from $4000-$4F36 (+1 Word, for the End of File 
Marker).  We can figure out EXACTLY what needs to be saved with a few simple 
calculations:

1) Calculate the number of bytes required: $4F36 - $4000 = $0F36 = 3894 bytes

2) Figure out how many words are needed by dividing the number of bytes by two:
3894 / 2 = 1947

3) Account for the End of File Marker: 1947 + 1 = 1948

If you don't account for the EOF Marker, then you're going to clobber the last 
word of your ML routine.

The following command will save EXACTLY what is needed:

PRINT ";STOP";:PRINT %(16384),1948

I can't think of any reason why saving all of RAM (2000 words) wouldn't work 
all of the time.  Yet, it IS nice to know a little bit about what is going on 
and how to save EXACTLY what you want saved.

Thanks to everyone that chipped in to help solve this problem.
